package com.ww.springboot.boot.algorithm.leetcode1;

/**
 * 描述：
 * 38. 外观数列
 *
 * @author 🧑 ‍wanwei
 * @since 2022-03-09 15:09
 */
public class AB38 {
    public static void main(String[] args) {
        System.out.println(countAndSay(30));
    }

    public static String countAndSay(int n) {
        if (n == 1) {
            return "1";
        }
        String info = countAndSay(n - 1);
        String result = "";
        char num = info.charAt(0);
        int count = 1;
        for (int i = 1; i < info.length(); i++) {
            if (num == info.charAt(i)) {
                count++;
            } else {
                result += count + "" + num;
                num = info.charAt(i);
                count = 1;
            }
        }
        result += count + "" + num;
        return result;
    }
}
